package _05处理流;

import java.io.*;

public class DataStreamDemo {

    public static void main(String[] args) throws IOException {

        //
//		testWrite();

        testRead();
    }

    private static void testRead() throws IOException {

        // 1.
        DataInputStream in = new DataInputStream(new FileInputStream("d:/2.data"));


        // 2.
        // 必须按照存入顺序读
        System.out.println(in.readBoolean());
        System.out.println(in.readByte());
        System.out.println(in.readShort());
        System.out.println(in.readInt());
        System.out.println(in.readLong());
        System.out.println(in.readFloat());
        System.out.println(in.readDouble());
        System.out.println(in.readChar());
        System.out.println(in.readChar());
        System.out.println(in.readChar());
        System.out.println(in.readChar());
        System.out.println(in.readUTF());


        // 3.
        in.close();
    }

    private static void testWrite() throws IOException {

        // 1. 新建流
        DataOutputStream os = new DataOutputStream(new FileOutputStream("d:/2.data"));

        // 2. 写入
        os.writeBoolean(true);// 4/1

        os.writeByte(10);// 1
        os.writeShort(10);// 2
        os.writeInt(10);// 4
        os.writeLong(10);// 8

        os.writeFloat(3.14F);// 4
        os.writeDouble(3.14);// 8

        os.writeChar('A');// 2
        os.writeChars("abc");// 2*3

        os.writeUTF("你好");// 3*2


        // 3. 关闭流
        os.close();

    }

}